function GRArea({ map, url }) {
  this.map = map;
  this.url = url;
  this.source = null;
  this.vectorLayer = null;
  this.interaction = null;
  this.feature = null;
}
GRArea.prototype.init = function () {
  if (!this.map) { return }
  this.source = new ol.source.Vector({ wrapX: false });
  this.vectorLayer = new ol.layer.Vector({
    source: this.source
  });
  this.map.addLayer(this.vectorLayer);
  this.interaction = new ol.interaction.Draw({
    source: this.source,
    type: "Polygon"
  });
}
GRArea.prototype.onDraw = function ({ success, error }) {
  const this_ = this;
  this.interaction.on('drawstart', function (evt) {
    this.feature = evt.feature;
  });
  this.interaction.on('drawend', function () {
    const areaMeasureParam = new ol.supermap.MeasureParameters(this.feature.getGeometry());
    new ol.supermap.MeasureService(this_.url, { measureMode: "" })
      .measureArea(areaMeasureParam)
      .then(function (serviceResult) {
        if (serviceResult.type === 'processCompleted') {
          if (success) {
            success(serviceResult.result.area)
          }
        } else {
          if (error) {
            error('error')
          }
        }
      });
  });
  this.map.addInteraction(this.interaction);
}
GRArea.prototype.destroy = function () {
  this.map.removeInteraction(this.interaction);
  this.map.removeLayer(this.vectorLayer);
  this.source = null;
  this.vectorLayer = null;
  this.interaction = null;
  this.feature = null;
}
export default GRArea;